home *** CD-ROM | disk | FTP | other *** search
/ AMIGA-CD 2 / Amiga-CD - Volume 2.iso / ungepackte_daten / 1994 / 8 / 05 / term-4.0-source.lha / termAmigaGuide.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-17  |  7.1 KB  |  395 lines

  1. /*
  2. **    termAmigaGuide.c
  3. **
  4. **    AmigaGuide support routines
  5. **
  6. **    Copyright © 1990-1993 by Olaf `Olsen' Barthel
  7. **        All Rights Reserved
  8. */
  9.  
  10. #include "termGlobal.h"
  11.  
  12.     /* Local data. */
  13.  
  14. STATIC STRPTR             ContextList[35];
  15. STATIC AMIGAGUIDECONTEXT     Context;
  16. STATIC struct NewAmigaGuide     NewGuide;
  17. STATIC struct Process        *GuideProcess;
  18. STATIC LONG             GuideContextID = CONTEXT_MAIN;
  19. STATIC BOOLEAN             Trouble,
  20.                  Waiting = TRUE;
  21.  
  22.     /* GuideServer(VOID):
  23.      *
  24.      *    AmigaGuide server, handles all the signal processing.
  25.      */
  26.  
  27. STATIC VOID __saveds
  28. GuideServer(VOID)
  29. {
  30.     if(Trouble)
  31.     {
  32.         Signal(ThisProcess,SIG_HANDSHAKE);
  33.  
  34.         Context = OpenAmigaGuide(&NewGuide,TAG_DONE);
  35.  
  36.         CloseAmigaGuide(Context);
  37.     }
  38.     else
  39.     {
  40.             /* Open the help text file asynchronously... */
  41.     
  42.         if(Context = OpenAmigaGuideAsync(&NewGuide,TAG_DONE))
  43.         {
  44.             ULONG    GuideMask,
  45.                 Signals;
  46.             BYTE    Done = FALSE;
  47.     
  48.                 /* Pick up the signal notification mask. */
  49.     
  50.             GuideMask = AmigaGuideSignal(Context);
  51.     
  52.                 /* Clear the context stack. */
  53.     
  54.             SetAmigaGuideContext(Context,0,TAG_DONE);
  55.     
  56.                 /* Flag the main process to continue. */
  57.     
  58.             Signal(ThisProcess,SIG_HANDSHAKE);
  59.     
  60.                 /* Go into input loop. */
  61.     
  62.             do
  63.             {
  64.                     /* Wait for a signal... */
  65.     
  66.                 Signals = Wait(SIG_KILL | GuideMask);
  67.     
  68.                     /* Are we to quit? */
  69.     
  70.                 if(Signals & SIG_KILL)
  71.                     Done = TRUE;
  72.     
  73.                     /* Process icoming AmigaGuide messages. */
  74.     
  75.                 if(Signals & GuideMask)
  76.                 {
  77.                     struct AmigaGuideMsg *GuideMessage;
  78.     
  79.                     while(GuideMessage = GetAmigaGuideMsg(Context))
  80.                         ReplyAmigaGuideMsg(GuideMessage);
  81.                 }
  82.             }
  83.             while(!Done);
  84.     
  85.                 /* Close the help text file. */
  86.     
  87.             CloseAmigaGuide(Context);
  88.         }
  89.     }
  90.  
  91.         /* Lock & quit. */
  92.  
  93.     Forbid();
  94.  
  95.     GuideProcess = NULL;
  96.  
  97.     if(Waiting)
  98.         Signal(ThisProcess,SIG_HANDSHAKE);
  99. }
  100.  
  101.     /* GuideLaunch(LONG ContextID):
  102.      *
  103.      *    Launch the AmigaGuide help file server.
  104.      */
  105.  
  106. STATIC BYTE
  107. GuideLaunch(LONG ContextID)
  108. {
  109.         /* Is the main program running and is this the
  110.          * main program to make the call?
  111.          */
  112.  
  113.     if(Window && SysBase -> ThisTask == ThisProcess)
  114.     {
  115.             /* Is the help file server already running? */
  116.  
  117.         if(!GuideProcess)
  118.         {
  119.             if(!AmigaGuideBase)
  120.             {
  121.                 if(AmigaGuideBase = OpenLibrary("amigaguide.library",0))
  122.                     Trouble = (AmigaGuideBase -> lib_Version < 39);
  123.             }
  124.  
  125.             if(AmigaGuideBase)
  126.             {
  127.                 BYTE IsValidFile = TRUE;
  128.  
  129.                     /* Do we have a valid AmigaGuide file name? */
  130.  
  131.                 if(Config -> PathConfig -> HelpFile[0])
  132.                 {
  133.                     if(!GetFileSize(Config -> PathConfig -> HelpFile))
  134.                         IsValidFile = FALSE;
  135.                 }
  136.                 else
  137.                     IsValidFile = FALSE;
  138.  
  139.                     /* Do we have a valid AmigaGuide file name? */
  140.  
  141.                 if(!IsValidFile)
  142.                 {
  143.                         /* Don't pop up the file requester if any
  144.                          * time-critical services are currently running!
  145.                          */
  146.  
  147.                     if(ContextID == CONTEXT_TRANSFER || ContextID == CONTEXT_DIAL)
  148.                     {
  149.                         DisplayBeep(Window -> WScreen);
  150.  
  151.                         return(FALSE);
  152.                     }
  153.                     else
  154.                     {
  155.                         struct FileRequester    *FileRequest;
  156.                         UBYTE             DummyBuffer[MAX_FILENAME_LENGTH],
  157.                                      DummyName[40];
  158.  
  159.                             /* Provide a default name if necessary. */
  160.  
  161.                         if(!Config -> PathConfig -> HelpFile[0])
  162.                             strcpy(Config -> PathConfig -> HelpFile,"PROGDIR:term.guide");
  163.  
  164.                             /* Block the windows. */
  165.  
  166.                         BlockWindows();
  167.  
  168.                             /* Get file and path name. */
  169.  
  170.                         strcpy(DummyBuffer,Config -> PathConfig -> HelpFile);
  171.  
  172.                         if(DummyBuffer[0])
  173.                         {
  174.                             STRPTR DummyChar;
  175.  
  176.                             if(FilePart(DummyBuffer) == DummyBuffer)
  177.                             {
  178.                                 strcpy(DummyName,DummyBuffer);
  179.  
  180.                                 DummyBuffer[0] = 0;
  181.                             }
  182.                             else
  183.                             {
  184.                                 strcpy(DummyName,FilePart(DummyBuffer));
  185.  
  186.                                 DummyChar = PathPart(DummyBuffer);
  187.  
  188.                                 *DummyChar = 0;
  189.                             }
  190.                         }
  191.                         else
  192.                             DummyName[0] = 0;
  193.  
  194.                             /* Get the help text file name. */
  195.  
  196.                         if(FileRequest = GetFile(Window,LocaleString(MSG_PATHPANEL_SELECT_HELP_FILE_TXT),DummyBuffer,DummyName,DummyBuffer,NULL,FALSE,FALSE,FALSE,LocaleString(MSG_GLOBAL_SELECT_TXT),TRUE))
  197.                         {
  198.                             if(GetFileSize(DummyBuffer))
  199.                             {
  200.                                 strcpy(Config -> PathConfig -> HelpFile,DummyBuffer);
  201.  
  202.                                 IsValidFile = TRUE;
  203.                             }
  204.  
  205.                             FreeAslRequest(FileRequest);
  206.                         }
  207.  
  208.                             /* Release the windows... */
  209.  
  210.                         ReleaseWindows();
  211.                     }
  212.                 }
  213.  
  214.                     /* Do we finally have a valid file name? */
  215.  
  216.                 if(IsValidFile)
  217.                 {
  218.                         /* Provide the context node names (note: language
  219.                          * specific!).
  220.                          */
  221.  
  222.                     LocalizeString(ContextList,MSG_TERMAMIGAGUIDE_NODE_00_TXT,MSG_TERMAMIGAGUIDE_NODE_32_TXT);
  223.  
  224.                     ContextList[33] = LocaleString(MSG_TERMAMIGAGUIDE_NODE_33_TXT);
  225.  
  226.                         /* Clear the instance. */
  227.  
  228.                     memset(&NewGuide,0,sizeof(struct NewAmigaGuide));
  229.  
  230.                         /* Fill in the structure. */
  231.  
  232.                     NewGuide . nag_BaseName        = "termHelp";
  233.                     NewGuide . nag_Name        = Config -> PathConfig -> HelpFile;
  234.                     NewGuide . nag_ClientPort    = "TERM_HELP";
  235.                     NewGuide . nag_Context        = ContextList;
  236.                     NewGuide . nag_Screen        = Window -> WScreen;
  237.  
  238.                         /* Launch the server process and
  239.                          * wait for reply.
  240.                          */
  241.  
  242.                     Forbid();
  243.  
  244.                     Waiting = TRUE;
  245.  
  246.                     if(GuideProcess = CreateNewProcTags(
  247.                         NP_Entry,    GuideServer,
  248.                         NP_Name,    "term AmigaGuide Process",
  249.                     TAG_DONE))
  250.                     {
  251.                         ClrSignal(SIG_HANDSHAKE);
  252.  
  253.                         Wait(SIG_HANDSHAKE);
  254.                     }
  255.  
  256.                     Waiting = FALSE;
  257.  
  258.                     Permit();
  259.                 }
  260.             }
  261.         }
  262.  
  263.             /* Pop the main screen to the front if necessary. */
  264.  
  265.         if(GuideProcess)
  266.         {
  267.             ScreenToFront(Window -> WScreen);
  268.  
  269.             return(TRUE);
  270.         }
  271.         else
  272.         {
  273.             if(AmigaGuideBase)
  274.             {
  275.                 CloseLibrary(AmigaGuideBase);
  276.  
  277.                 AmigaGuideBase = NULL;
  278.             }
  279.  
  280.             DisplayBeep(Window -> WScreen);
  281.  
  282.             return(FALSE);
  283.         }
  284.     }
  285.     else
  286.     {
  287.         if(GuideProcess && Window)
  288.         {
  289.             ScreenToFront(Window -> WScreen);
  290.  
  291.             return(TRUE);
  292.         }
  293.         else
  294.             return(FALSE);
  295.     }
  296. }
  297.  
  298.     /* GuideCleanup():
  299.      *
  300.      *    Terminate the AmigaGuide server and free the
  301.      *    associated resources.
  302.      */
  303.  
  304. VOID
  305. GuideCleanup()
  306. {
  307.     if(GuideProcess)
  308.     {
  309.         Forbid();
  310.  
  311.         Waiting = TRUE;
  312.  
  313.         if(Trouble)
  314.         {
  315.             MyEasyRequest(Window,LocaleString(MSG_V36_1830),LocaleString(MSG_GLOBAL_CONTINUE_TXT));
  316.  
  317.             SendAmigaGuideCmd(Context,"QUIT",NULL);
  318.         }
  319.         else
  320.             Signal(GuideProcess,SIG_KILL);
  321.  
  322.         ClrSignal(SIG_HANDSHAKE);
  323.  
  324.         Wait(SIG_HANDSHAKE);
  325.  
  326.         Permit();
  327.     }
  328.  
  329.     if(AmigaGuideBase)
  330.     {
  331.         CloseLibrary(AmigaGuideBase);
  332.  
  333.         AmigaGuideBase = NULL;
  334.     }
  335. }
  336.  
  337.     /* GuideContext(LONG NewContextID):
  338.      *
  339.      *    Set the global AmigaGuide context.
  340.      */
  341.  
  342. VOID __regargs
  343. GuideContext(LONG NewContextID)
  344. {
  345.     GuideContextID = NewContextID;
  346. }
  347.  
  348. ULONG __saveds __asm
  349. GuideSetupHook(register __a0 struct Hook *Hook,register __a1 struct LayoutHandle *Handle,register __a2 LONG GadgetID)
  350. {
  351.     if(GuideLaunch(GuideContextID))
  352.     {
  353.         SendAmigaGuideCmd(Context,NULL,
  354.             AGA_Context,GuideContextID,
  355.         TAG_DONE);
  356.  
  357.         return(TRUE);
  358.     }
  359.     else
  360.         return(FALSE);
  361. }
  362.  
  363.     /* GuideSetup():
  364.      *
  365.      *    Try to display the currently selected AmigaGuide
  366.      *    help text.
  367.      */
  368.  
  369. VOID
  370. GuideSetup()
  371. {
  372.     if(GuideLaunch(GuideContextID))
  373.     {
  374.         SendAmigaGuideCmd(Context,NULL,
  375.             AGA_Context,GuideContextID,
  376.         TAG_DONE);
  377.     }
  378. }
  379.  
  380.     /* GuideDisplay(LONG ContextID):
  381.      *
  382.      *    Try to display an AmigaGuide help text.
  383.      */
  384.  
  385. VOID __regargs
  386. GuideDisplay(LONG ContextID)
  387. {
  388.     if(GuideLaunch(ContextID))
  389.     {
  390.         SendAmigaGuideCmd(Context,NULL,
  391.             AGA_Context,ContextID,
  392.         TAG_DONE);
  393.     }
  394. }
  395.